/*
 * @Author       : 刘洋 liuy5335@163.com
 * @Date         : 2024-05-15 14:53:57
 * @LastEditors: ZJP 2712104231@qq.com
 * @LastEditTime: 2025-02-28 14:03:15
 * @FilePath: \zhlx-autoform-ui\install.js
 * @Description  : 介绍文件的作用
 * 
 * Copyright (c) 2024 by zhlx - liuy5335@163.com, All Rights Reserved. 
 */
import axios from 'axios'

import VFormDesigner from '@/components/form-designer/index.vue'
import VFormRender from '@/components/form-render/index.vue'

import Draggable from '@/../lib/vuedraggable/dist/vuedraggable.umd.js'
import {registerIcon} from '@/utils/el-icons'
import 'virtual:svg-icons-register'
import '@/iconfont/iconfont.css'
import '@/assets/iconfont/index.css'
import '@/assets/scss/dialog.scss'

import ContainerWidgets from '@/components/form-designer/form-widget/container-widget/index'
import ContainerItems from '@/components/form-render/container-item/index'

import TableMultiLevelColumn from '@/components/form-designer/form-widget/table-multi-level-column'
import TableHighLevelColumn from '@/components/form-render/table-high-level-column'

import { addDirective } from '@/utils/directive'
import { loadExtension } from '@/extension/extension-loader'

// sdk import begin
import {
  addContainerWidgetSchema,
  addBasicFieldSchema,
  addAdvancedFieldSchema,
  addOrganizeFiledschema,
  addBusinessFieldschema,
  addAuxiliaryFieldschema,
  addCustomWidgetSchema, addChartContainerSchema, addChartSchema
} from '@/components/form-designer/widget-panel/widgetsConfig'
import * as PERegister from '@/components/form-designer/setting-panel/propertyRegister'
import * as PEFactory from '@/components/form-designer/setting-panel/property-editor-factory.jsx'
import {
  registerCWGenerator,
  registerFWGenerator
} from '@/utils/sfc-generator'

import i18n, {addENExtensionLang, addZHExtensionLang} from "@/utils/i18n"
import * as Utils from '@/utils/util'
import containerMixin from "@/components/form-designer/form-widget/container-widget/containerMixin"
import ContainerWrapper from "@/components/form-designer/form-widget/container-widget/container-wrapper"
import FieldComponents from '@/components/form-designer/form-widget/field-widget/index'
import refMixinDesign from "@/components/form-designer/refMixinDesign"

import refMixin from "@/components/form-render/refMixin"
import ContainerItemWrapper from '@/components/form-render/container-item/container-item-wrapper'
import containerItemMixin from "@/components/form-render/container-item/containerItemMixin"

import StaticContentWrapper from '@/components/form-designer/form-widget/field-widget/static-content-wrapper'
import FormItemWrapper from '@/components/form-designer/form-widget/field-widget/form-item-wrapper'
import emitter from '@/utils/emitter'
import eventBus from '@/utils/event-bus'
import fieldMixin from "@/components/form-designer/form-widget/field-widget/fieldMixin"
import eventMixin from "@/components/form-designer/setting-panel/property-editor/event-handler/eventMixin"
import ZHLXCommonSelect from '@/components/ZHLX-Components/common/commonSelect/index2.vue' // 选人组件
import ZHLXFileList from '@/components/ZHLX-Components/ZHLX-uploadView/index.vue' // 附件列表组件
import ZHLXWpsWord from '@/components/ZHLX-Components/ZHLX-wpsWord/index.vue' // wpsword组件
import ZHLXWpsPdf from '@/components/ZHLX-Components/ZHLX-wpsPdf/index.vue' // wpsPdf组件
import ZHLXDocumentNumber from '@/components/ZHLX-Components/ZHLX-documentNumber/index.vue' // 文号组件
import ZHLXCarbonCopy from '@/components/ZHLX-Components/ZHLX-unitSelect/index.vue' // 抄送组件
import ZHLXDateRange from '@/components/ZHLX-Components/ZHLX-dateRange/index.vue' // 抄送组件
import ZHLXBatchImport from '@/components/ZHLX-Components/ZHLX-batchImport/index.vue' // 批量导入组件
import ZHLXSelectFields from '@/components/ZHLX-Components/ZHLX-selectFields/index.vue' // 批量导入组件


// sdk import end

// 引入lib包所需公共样式
import '@/assets/scss/common.scss'

VFormDesigner.install = function (app) {
  addDirective(app)
  loadExtension(app)

  app.use(ContainerWidgets)
  app.use(ContainerItems)

  registerIcon(app)
  app.component('draggable', Draggable)
  app.component(VFormDesigner.name, VFormDesigner)
  app.component(TableMultiLevelColumn.name, TableMultiLevelColumn)
  app.component(TableHighLevelColumn.name, TableHighLevelColumn)
}

VFormRender.install = function (app) {
  loadExtension(app)

  app.use(ContainerItems)

  registerIcon(app)
  app.component(VFormRender.name, VFormRender)
  app.component(TableHighLevelColumn.name, TableHighLevelColumn)
}

const components = [
  VFormDesigner,
  VFormRender,
  TableMultiLevelColumn,
  TableHighLevelColumn
]

const install = (app) => {
  addDirective(app)
  loadExtension(app)

  app.use(ContainerWidgets)
  app.use(ContainerItems)

  registerIcon(app)
  app.component('draggable', Draggable)

  components.forEach(component => {
    app.component(component.name, component)
  })

  window.axios = axios
}

if (typeof window !== 'undefined' && window.Vue) { /* script方式引入时赋值axios！！ */
  //window.axios = axios
}

/**
 * 导出二开组件所需的所有对象、工具方法及组件
 */
const VFormSDK = {
  addContainerWidgetSchema,
  addBasicFieldSchema,
  addAdvancedFieldSchema,
  addOrganizeFiledschema,
  addBusinessFieldschema,
  addAuxiliaryFieldschema,
  addCustomWidgetSchema,
  addChartContainerSchema,
  addChartSchema,
  PERegister,
  PEFactory,
  registerCWGenerator,
  registerFWGenerator,
  addZHExtensionLang,
  addENExtensionLang,

  i18n,
  Utils,
  containerMixin,
  Draggable,
  ContainerWrapper,
  FieldComponents,
  refMixinDesign,

  ContainerItemWrapper,
  containerItemMixin,
  refMixin,

  StaticContentWrapper,
  ZHLXCommonSelect,
  ZHLXFileList,
  ZHLXWpsWord,
  ZHLXWpsPdf,
  ZHLXDocumentNumber,
  ZHLXCarbonCopy,
  ZHLXDateRange,
  ZHLXBatchImport,
  ZHLXSelectFields,
  FormItemWrapper,
  emitter,
  eventBus,
  fieldMixin,
  eventMixin,
}

export default {
  install,
  VFormDesigner,
  VFormRender,
  VFormSDK
}
